<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Blog/classes/PhpFox_ComponentView.class.php, $Author:  $ */



/** Component for viewing any blog
 *
 * @version $Id: PhpFox_ComponentView.class.php 133 2007-12-28 15:43:39Z phpfoxsv $
 * @package module.blog
 */
class PhpFox_Mod_Blog_ComponentView extends BaseComponent
{
    function process()
    {
        $oBlogItem = $this->_oModule->getItem('Blog');
        /* @var $oBlogItem PhpFox_Mod_Blog_ItemBlog */
        $oSecurityService = App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oReq = &App::getRequest();
        $oTpl = $this->_oModule->getTemplate();

        $oSecurityService->checkPerm('blog', array('read_only', 'full'));
        $oSecurityService->checkAccess('blogs');
        if (!$iId = $oReq->getInt('id'))
        {
        	App::gotoUrl('public.blog.main');
        }

        $aBlog = $this->oDatabase->getRow("SELECT j.id, j.user_id, j.title, j.text, j.time, j.view, j.tags, u.user FROM
        	". App::getT('journal') ." AS j
        	LEFT JOIN ". App::getT('user') ." AS u ON(j.user_id = u.id)
        	WHERE j.id = '". $iId ."'
        	");

		if ( !isset($aBlog['id']) )
		{
			App::gotoUrl('public.blog.main');
		}

		$aBlog['view']++;
		$this->oDatabase->update(App::getT('journal'), array('view' => $aBlog['view']), " id = '". $aBlog['id'] ."' ");

		App::loadClass('Text');
        $oTxt = &new Text();
        $aBlog['tags'] = $oTxt->_splitString($aBlog['tags'], 15);
        
        $oTpl->assignSrc('aItem', $aBlog);
        $oTpl->assign(array(
        	'sUImageUrl'       => App::getParam('user.pic.url'),
        ));
        return $oTpl->fetch('View.html');
    }
}
?>